<link rel="stylesheet" type="text/css" href="../stylesheet/style.css"/>
<?php
/*
* @author Nguyen Xuan Hong
* @copyright 2011
*/

require_once('../includes/class.tbl.php');

if($_GET['mode'] == 'listclass')
{
	$pClsClass = new clsClassTable();	
	if($pClsClass->avaibleSubmit()){
		$pClsClass->loadBuffer();
		$pClsClass->insertDB();
		echo acpredirect();
		exit();
	}
	echo $pClsClass->createForm('Thêm lớp học');
	
	require_once('../includes/templates.php');
	$table = new clsTable('lstclass',array(array("ID", "1"),array("Tên lớp", 0),array("Sửa", 1),array("Xóa", 1)));
	$list_album = $pClsClass->listobj($branch_id);
	foreach($list_album as $class){
		$html_remove =      '<a href="?page=class&mode=deleteclass&id='.$class->value('id').'">Xóa</a>';
		$html_edit = 	'<a href="?page=class&mode=editclass&id='.$class->value('id').'">Sửa</a>';	
		$table->addRow($class->value('id'),array($class->value('id'),$class->value('name'),$html_edit,$html_remove));
	}
	echo $table->putHTML(true);
	exit();
}

if($_GET['mode'] == 'deleteclass'){		
	// Redefine insert
	$deleteid = sget('id');			
	$pClsClass = new clsClassTable($deleteid);
	if(!$_POST['submit']){
		?>
        
	<center><div class="notification warning">
        <span></span>
        <p><strong>Warning!</strong> 
        	<div class="text">Bạn có muốn xóa Lớp học này không</div> 
            <div class="btn"><form method='post'><input type='submit' name='submit' value = 'Xóa' /></form></div>
         </p>
	</div></center>
        <?
		exit();
	}
	$pClsClass->removeDB('id', $deleteid);
       header("location:index.php?page=class&mode=listclass");
	exit();
}

if($_GET['mode'] == 'editclass')
{
	$edit = (int)sget('id');
	$pClsClass = new clsClassTable($deleteid);
	if($pClsClass->avaibleSubmit()){
		$pClsClass->loadBuffer();
		$pClsClass->updateDB('id',$edit);
        echo acpredirect('page=class&mode=listclass');
		exit();
	}
	$pClsClass->loadDB('id',$edit);
       echo $pClsClass->createForm('Sửa tên lớp');
	exit();
}
  
?> 














  